package com.cbwl.eoas.cms.web.controller.sysconfig;

import java.util.Date;

import javax.servlet.http.HttpServletRequest;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.cbwl.eoas.cms.api.sysconfig.IDictRegionService;
import com.cbwl.eoas.cms.model.sysconfig.DictRegionDTO;
import com.cbwl.eoas.common.framework.session.SessionManager;
import com.cbwl.eoas.common.framework.vo.PageRequest;



/**
 * 
 * <p>[描述信息：行政区域管理Controller]</p>
 *
 * @author 虞云波 - yuyunbo@3856.cc
 * @version 1.0 Created on 2017年10月12日 下午13:29:23
 */
@Controller
@RequestMapping("/dictregion")
public class DictRegionController {
	
	//业务层注解
	@Autowired
	private IDictRegionService dictRegionService;
	
	private static Logger logger = LoggerFactory.getLogger(DictRegionController.class);
	
	
	/**
	 * <p>初始化界面</p>
	 * 
	 * @return
	 * @author 虞云波 - yuyunbo@3856.cc
	 * @version 1.0 Created on 2017年10月12日 下午13:29:23
	 */
	@RequestMapping("/initDictRegion")
	public String initDictRegionPage() {
		return "initDictRegion";
	}


	/**
	 * <p>初始化新增修改界面</p>
	 * 
	 * @return
	 * @author 虞云波 - yuyunbo@3856.cc
	 * @version 1.0 Created on 2017年10月12日 下午13:29:23
	 */
	@RequestMapping("/initAddUpdateDictRegionPage")
	public String initAddUpdateDictRegionPage(HttpServletRequest request,DictRegionDTO bean) {
		request.setAttribute("bean", bean);
		return "initAddUpdateDictRegionPage";
	}
	

	/**
	 * <p>查询（分页）</p>
	 * 
	 * @param bean
	 * @return
	 * @author 虞云波 - yuyunbo@3856.cc
	 * @version 1.0 Created on 2017年10月12日 下午13:29:23
	 */
	@RequestMapping("/queryDictRegionPage")
	@ResponseBody
	public Object queryDictRegionPage(DictRegionDTO bean,PageRequest pageRequest) {
		return dictRegionService.queryPageList(bean,pageRequest);
	}

	/**
	 * 
	 * <p>通过id查询主体信息</p>
	 * 
	 * @param bean
	 * @return
	 * @author 虞云波 - yuyunbo@3856.cc
	 * @version 1.0 Created on 2017年10月12日 下午13:29:23
	 */
	@RequestMapping("/getDictRegionById")
	@ResponseBody
	public Object getDictRegionById(DictRegionDTO bean) {
		return dictRegionService.getObjectById(bean);
	}

	/**
	 * 
	 * <p>保存主体信息</p>
	 * 
	 * @param bean
	 * @return
	 * @author 虞云波 - yuyunbo@3856.cc
	 * @version 1.0 Created on 2017年10月12日 下午13:29:23
	 */
	@RequestMapping("/saveDictRegion")
	@ResponseBody
	public Object saveDictRegion(DictRegionDTO bean) throws Exception {


		bean.setGmtCreate(new Date());
		bean.setCreater(SessionManager.getCurrentUser().getId());
		logger.info("{}新建了区域信息,区域名称{}", SessionManager.getCurrentUser().getEmpName(),bean.getName());
		return dictRegionService.saveObject(bean);
	}

	/**
	 * 
	 * <p>更新主体信息</p>
	 * 
	 * @param bean
	 * @return
	 * @author 虞云波 - yuyunbo@3856.cc
	 * @version 1.0 Created on 2017年10月12日 下午13:29:23
	 */
	@RequestMapping("/updateDictRegion")
	@ResponseBody
	public Object updateDictRegion(DictRegionDTO bean) throws Exception {		
		bean.setGmtModified(new Date());
		bean.setModifier(SessionManager.getCurrentUser().getId());
		logger.info("{}修改了区域信息,区域名称{}", SessionManager.getCurrentUser().getEmpName(),bean.getName());
		return dictRegionService.updateObject(bean);
	}

	/**
	 * 
	 * <p>删除主体信息</p>
	 * 
	 * @param bean
	 * @return
	 * @author 虞云波 - yuyunbo@3856.cc 
	 * @version 1.0 Created on 2017年10月12日 下午13:29:23
	 * @throws Exception 
	 */
	@RequestMapping("/deleteDictRegion")
	@ResponseBody
	public Object deleteDictRegion(DictRegionDTO bean) throws Exception {
		logger.info("{}删除了区域信息,区域名称{}", SessionManager.getCurrentUser().getEmpName(),bean.getName());
		return dictRegionService.deleteObject(bean);
	}
}
